<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class WxUser extends Model
{
    use HasFactory;

    protected $table = 'wx_user';

    protected $guarded = [];

    /**
     * @param $openid
     * @return mixed
     * 通过openid获取用户信息
     */
    public static function getUserInfo($openid)
    {
        return self::where('openid',$openid)->first();
    }

    public static function updateUserInfo($user_id,$data)
    {
        return self::where('id',$user_id)->update($data);
    }

    public static function createUser($data)
    {
        return self::create($data);
    }

    public static function wxLogin($phone)
    {
        $res= self::where('phone',$phone)->first();
        if (!$res){
            self::create(['phone'=>$phone]);
        }
        return self::where('phone',$phone)->first();
    }
    public static function details($user_id)
    {
        return self::where('id',$user_id)->first();
    }
}
